const reqInterface = require('../../../../api/models')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    houseList: null,
    roomList: [],
    info: {
      house_id: 0,
      room_id: 0,
      name: '',
      content: '',
      phone: ''
    }
  },

  onShow() {
    this.getHouse()
  },

  submit() {
    let self = this;
    reqInterface.PostVisitor(self.data.info).then(res => {
      wx.showToast({
        title: '已通知业主，请待业主回应',
        icon: 'none'
      })
      // 1s后执行
      setTimeout(() => {
        wx.reLaunch({
          url: '/pages/home/index/index',
        })
      }, 1000)
    })
  },

  getHouse() {
    let self = this;
    reqInterface.GetHouses({
      page: 1,
      limit: 100,
      name: '',
      id: 0
    }).then(res => {
      self.setData({
        houseList: res
      })
    })
  },

  houseIdValue(e) {
    let self = this;
    self.setData({
      'info.house_id': e.detail.val
    })
    self.getRoom(e.detail.val)
  },

  getRoom(val) {
    let self = this;
    reqInterface.GetRooms({
      page: 1,
      limit: 100,
      house_id: val
    }).then(res => {
      self.setData({
        roomList: res
      })
    })
  },

  roomIdValue(e) {
    let self = this;
    self.setData({
      'info.room_id': e.detail.val
    })
  },

  nameValue(e) {
    let self = this;
    self.setData({
      'info.name': e.detail.val
    })
  },

  contentValue(e) {
    let self = this;
    self.setData({
      'info.content': e.detail.val
    })
  },


  phoneValue(e) {
    let self = this;
    self.setData({
      'info.phone': e.detail.val
    })
  },


})